package cn.barudisshu.orm.transaction;

import cn.barudisshu.log.Logger;
import cn.barudisshu.orm.aspect.Aspect;
import cn.barudisshu.orm.aspect.AspectHandler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author Barudisshu
 */
public class TransactionAspect implements Aspect {

    private static final Logger logger = Logger.getLogger(AspectHandler.class);

    public Object aspect(InvocationHandler ih, Object proxy, Method method, Object[] args) throws Throwable {
        Object result = null;

        Transaction transactionAnn = method.getAnnotation(Transaction.class);
        if (transactionAnn != null) {

            // TODO: 获取注解信息或设置值
            String[] names = transactionAnn.name();

            //执行操作
            result = ih.invoke(proxy, method, args);

            // TODO: 处理
        } else {
            //执行操作
            result = ih.invoke(proxy, method, args);
        }
        return result;
    }

}
